package com.msb.dp.singleton;

/**
 * @Auther: Huanyu Lee
 * @Date: 2022/3/2  22:51
 * @Description: 改进版的懒汉式 “完美”版
 *  双重检查
 *  但依然不能避免反序列化
 */
public class Mgr05 {
    private static volatile Mgr05 INSTANCE; // JIT
    private Mgr05(){}
    public static Mgr05 getInstance(){
        if (INSTANCE == null) {
            synchronized (Mgr05.class){
                if (INSTANCE == null) {
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    INSTANCE = new Mgr05();
                }
            }
        }
        return INSTANCE;
    }
}
